package com.atguigu.controller;

import com.atguigu.annotation.Log;
import com.atguigu.entity.product.Brand;
import com.atguigu.service.BrandService;
import com.atguigu.vo.common.Result;
import com.atguigu.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "品牌管理")
@RestController
@RequestMapping("/product/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    @Operation(summary = "新增")
    @PostMapping("/submit")
    public Result submit(@RequestBody Brand brand) {
        brandService.submit(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除")
    @GetMapping("/remove/{brandId}")
    public Result remove(@PathVariable Long brandId) {
        brandService.remove(brandId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改")
    @PostMapping("/update")
    public Result update(@RequestBody Brand brand) {
        brandService.update(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Log(title = "品牌：分页", businessType = 0)
    @Operation(summary = "分页")
    @GetMapping("/page/{current}/{limit}")
    public Result page(@PathVariable Integer current, @PathVariable Integer limit) {
        PageInfo<Brand> brandList = brandService.page(current, limit);
        return Result.build(brandList, ResultCodeEnum.SUCCESS);
    }
}
